Snow Depth Temperature climatology analysis
Hadleigh Thompson
Northern Hydrometerology Group
UNBC
Feb 2017
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import plotly.plotly as py
import cufflinks as cf
import pandas as pd
cf.set_config_file(offline=True, theme='ggplot')
plt.style.use('ggplot')
% matplotlib inline
columns = ['Snow_Depth']
snow_profile = pd.DataFrame(columns=columns)
snow_profile.head()
for file in [f for f in os.listdir('../Data/QRRC/') if f.endswith('.xlsx')]:
file_path = os.path.splitext(os.path.basename(file))
filename = file_path[0]
# read and convert Timestamp to pd DateTime object
df = pd.read_excel('../Data/QRRC/{}' .format(file), header=0, skiprows=(1,2), engine='xlrd')
df.Timestamp = pd.to_datetime(df.Timestamp, infer_datetime_format=True)
df.set_index(['Timestamp'], inplace=True, drop=True)
# ensure the series is of the correct type to perform the required operations
series_snowdepth = df.DBTCDT.astype(float)
#series_snowdepth = series_snowdepth[(series_snowdepth >= 0.) & (series_snowdepth < 221.)]
# empty df to conncat to existing df to create long timeseries
snow_profile2 = pd.DataFrame()
snow_profile2['Snow_Depth'] = series_snowdepth
snow_profile2['Snow_Depth'][(snow_profile2.index.month >= 5) & (snow_profile2.index.month <= 9)] = 0.0
snow_profile = pd.concat([snow_profile, snow_profile2], axis=0)
print('Added {}' .format(filename))
snow_profile.sort_index(inplace=True)
snow_profile.iplot(kind='line', filename='cf-simple-line', color = 'rgb(100, 100, 235)',
title='Quick-look Plotly Trace 1')
snow_profile[(snow_profile['Snow_Depth'] < 0.) | (snow_profile['Snow_Depth'] > 221.)] = np.nan
snow_profile.iplot(kind='line', filename='cf-simple-line', color = 'rgb(100, 100, 235)',
title='Quick-look Plotly Trace 2')
snow_profile['Snow_Depth'][(snow_profile.index.month >= 5) & (snow_profile.index.month <= 10)] = 0.0
snow_profile.iplot(kind='line', filename='cf-simple-line', color='rgb(100,100,235)',
title='Quick-look Plotly Trace 3')
snow_profile.to_excel('../Data/Climatology_data/QRRC_Snow_Depth_Climatology.xlsx', sheet_name='Data', na_rep='Nan')